<?php
    session_start();

//  获取当前用户登录id
   $user_id = $_SESSION["id"] ?? 0;

//  获取用户的头像地址，如果没有上传则显示默认头像
function getAvatar($user_id){
    $head = "./img/{$user_id}.jpg";
    if(file_exists($head)){
        return $head."?". time();
    }
    return "./img/123.jpg";
}

class DB{
    public $pdo = null;
    public function __construct(){
         // 连接数据库
        $this -> pdo = new PDO("mysql:host=localhost;dbname=php_lyb;charset=utf8mb4","root","");
    }
    function write($sql){

        $stmt =$this-> pdo->prepare($sql);
        // 执行sql语句
        return $stmt -> execute();
    }

    function read($sql){
        $stmt =$this-> pdo->prepare($sql);
        $stmt->execute();

        return $res = $stmt->fetchAll();

    }
}

$db = new DB();
?>